package com.zhuchaooasystem.ui.home.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;

import com.zhuchaooasystem.R;
import com.zhuchaooasystem.adapter.MessageVPAdapter;
import com.zhuchaooasystem.base.BaseFragment;
import com.zhuchaooasystem.presenter.home.fragment.MessageContract;
import com.zhuchaooasystem.presenter.home.fragment.MessagePresenter;
import com.zhuchaooasystem.ui.home.message.InformMessageFragment;
import com.zhuchaooasystem.ui.home.message.ServiceMessageFragment;
import com.zhuchaooasystem.widget.ViewpagerNoScroll;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author yinsi
 */

public class MessageFragment extends BaseFragment<MessagePresenter> implements MessageContract.View {

    @BindView(R.id.fragment_message_vp)
    ViewpagerNoScroll fragmentMessageVp;
    @BindView(R.id.fragment_message_tab)
    TabLayout fragmentMessageTab;

    private List<Fragment> fragments;
    private List<String> titleList;

    private MessageVPAdapter adapter;

    @Override
    protected MessagePresenter getPresenter() {
        return new MessagePresenter(mContext, this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_message;
    }

    @Override
    protected void initVariables() {

    }

    @Override
    protected void initView() {
        fragments = new ArrayList<>();
        titleList = new ArrayList<>();

        fragments.add(new ServiceMessageFragment());
        fragments.add(new InformMessageFragment());

        titleList.add("服务消息");
        titleList.add("通知消息");

        adapter = new MessageVPAdapter(getChildFragmentManager(), titleList, fragments);

        fragmentMessageTab.setupWithViewPager(fragmentMessageVp);
        fragmentMessageVp.setAdapter(adapter);

    }

    @Override
    protected void initDataAndLoadData() {

    }

    public void changeTitle(String type, int size) {
        if (type.equals("service")) {
            titleList.set(0, "服务消息 " + size);
        } else if (type.equals("inform")) {
            titleList.set(1, "通知消息 " + size);
        }
        adapter.changeTitle(titleList);
    }

}
